package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.ProjectImage;
import com.chixing.ih.module.programmer.pojo.UserImage;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-28
 * Time: 0:25
 *
 * @version 1.0
 */
public class ImageMapperProvider {

    public String insertUserOne() {
        return new SQL() {{
            INSERT_INTO("tbl_user_image");
            VALUES("user_id", "#{userId}");
            VALUES("image_url", "#{imageUrl}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }

    public String insertProjectOne(ProjectImage projectImage) {
        return new SQL() {{
            INSERT_INTO("tbl_project_image");
            VALUES("project_id", "#{projectId}");
        }}.toString();
    }

    public String deleteOneById() {
        return null;
    }

    public String getOneByUserId() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_user_image");
            WHERE("user_id=#{userId} AND is_deleted=0 ");

        }}.toString();

    }

    public String getOneByProjectId() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_project_image");
            WHERE("project_id=#{projectId} AND is_deleted=0 ");

        }}.toString();

    }


    public String updateUserOne(UserImage image) {
        return new SQL() {
            {
                UPDATE("tbl_user_image");
                if (!EmptyUtil.isEmpty(image.getImageUrl())) {
                    SET("image_url=#{imageUrl}");
                }
                if (!EmptyUtil.isEmpty(image.getIsDeleted())) {
                    SET("is_deleted=#{isDeleted}");
                }
                if (!EmptyUtil.isEmpty(image.getIsLegal())) {
                    SET("is_legal=#{isLegal}");
                }
                WHERE("user_id=#{userId}");

            }
        }.toString();


    }

    public String updateProjectOne(ProjectImage projectImage) {
        return new SQL() {
            {
                UPDATE("tbl_project_image");
                if (!EmptyUtil.isEmpty(projectImage.getImageUrl())) {
                    SET("image_url=#{imageUrl}");
                }
                if (!EmptyUtil.isEmpty(projectImage.getIsDeleted())) {
                    SET("is_deleted=#{isDeleted}");
                }
                if (!EmptyUtil.isEmpty(projectImage.getIsLegal())) {
                    SET("is_legal=#{isLegal}");
                }
                WHERE("project_id=#{projectId}");

            }
        }.toString();


    }
}
